<template>
	<view>
		<view class="weatherBox">
			<text>{{time}}</text>
			<text>{{week}}</text>
			<text>{{city}}</text>
			<text>{{high}}</text>
			<text>{{low}}</text>
			<text>{{Wtype}}</text>
		</view>
		<view v-for="item in NewsList" style="margin: 5px;">
			<TopTextNews :title="item.title" :isTop="item.isTop" :author="item.author" :comment="item.comment"
				:isAd="item.isAd" :timedata="item.timedate" :images="item.images"></TopTextNews>
		</view>
	</view>
</template>

<script>
	import newsdata from '../../../data/news.json';
	import TopTextNews from '../../../components/TopTextNews.vue';
	export default {
		components: {
			TopTextNews
		},
		data() {
			return {
				NewsList: [],

				time: "",
				city: "",
				high: "",
				low: "",
				week:"",
				Wtype: ""
			}
		},
		methods: {
			getWeather() {
				uni.request({
					url: 'http://t.weather.sojson.com/api/weather/city/101230501',
					success: (res) => {
						console.log("success:" + res.data.time);
						this.time = res.data.data.forecast[0].ymd;
						this.week = res.data.data.forecast[0].week;
						this.city = res.data.cityInfo.city;
						this.high = res.data.data.forecast[0].high;
						this.low = res.data.data.forecast[0].low;
						this.Wtype = res.data.data.forecast[0].type;
					},
					fail: (eMsg) => {
						console.log("request fail:" + eMsg);
					}
				});
			},
			loadNewsData() {
				// 直接从导入的JSON文件获取数据
				this.NewsList = newsdata.NewsList;
			}
		},
		onLoad() {
			this.getWeather();
			this.loadNewsData();
		}
	}
</script>

<style>
	.weatherBox {
		display: flex;
		margin-top: 5px;
		font-size: 14px;
		justify-content: center;
		border-bottom: 1px solid #DDD;
	}

	.weatherBox>text {
		margin-right: 8px;
	}
</style>